import ballerina/math;
import ballerina/io;
//randomly picks two number between 1 and 200 and then computes the prime numbers in between the selected numbers.
public function main() {
int r1 = math:randomInRange(1, 200);
int r2 = math:randomInRange(1, 200);
// Make sure the numbers are not the same
while (r1 == r2) {
r1 = math:randomInRange(1, 200);
}
// Make sure r1 is always the smaller number
if (r1 > r2) {
int temp = r1;
r1 = r2;
r2 = temp;
}
int r1backup = r1;
int[] primes = [];
// Scan through all numbers adding to the prime array if they are prime
while (r1 < r2) {
int j = 2;
boolean prime = true;
while (j < (r1 - 1)) {
if ((r1 % j) == 0) {
// Not prime
prime = false;
}
j = j + 1;
}
if (prime) {
primes[primes.length()] = r1;
}
r1 = r1 + 1;
}
io:println("Lower bound: " + r1backup);
io:println("Upper bound: " + r2 + "\nPrimes: ");
io:print(primes);
io:println("");
}